<?php

    require "config.php"; // NOTE:It's a best practice to keep your private information in different file which has access to limited people

    $con = mysql_connect("localhost",$db_user ,$db_pass);
    error_reporting(0);	
    // if an error was encountered, the script exits with an error message
    if (!$con){
	die('Could not connect: ' . mysql_error());
    
    }

    mysql_select_db($db_name, $con); //connecting with the database
    $sql_fetch = "SELECT  s.courseId, c.courseNumber, s.courseSection, c.courseName, s.currentTerm, s.time, s.faculty, s.location FROM CourseSection s, Course c WHERE s.courseId =    c.courseId AND c.courseNumber ='$_POST[courseNumber]'";

    $result = mysql_query($sql_fetch); 
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Search Course Data</title>
</head>
<style>
html {
    overflow: scroll; 
}

.scrollable{
   overflow: auto;
   width: 70px; /* adjust this width depending to amount of text to display */
   height: 80px; /* adjust height depending on number of options to display */
   border: 1px silver solid;
 }
body{background-image:url('Images/sjsu logo.jpg');
background-repeat: no-repeat;
  background position: top center;
  background-size: 100%;
  background-size: 1400px 1200px;
  position:relative;}
  
h3.pos_fixed{
    color:#6D63A9;
    position:relative;
    top:25px;
    left:30px;
}

#b{
    position:relative;
    top:140px;
    left:320px;
}

a:link {
  /* Applies to all unvisited links */
  text-decoration:  none;
  font-weight:      bold;
  color:          "#blue";
  font-size:120%;
} 

</style>

<div id="b">
   <table border='1'>
   <tr> 
    <td><b>Select</b></td>
    <td><b>Course ID</b></td>
    <td><b>Course Number</b></td>
    <td><b>Course Section</b></td>
    <td><b>Course Name</b></td>
    <td><b>Current Term</b></td>
    <td><b>Time</b></td>
    <td><b>Faculty</b></td>
    <td><b>Location</b></td>
   </tr>
<div id = "e">
<? 
    session_start();
    $num_rows = mysql_num_rows($result);

    if ($num_rows == 0) {
       echo "Course does not exist <br> <br> <br>";
    }

    echo "<form action='insertEnrollment.php' method='post'>";
    while($row = mysql_fetch_array($result)){
	echo "<tr>";
	echo "<td> <input name='select[]' type='checkbox' value='$row[courseNumber]:$row[courseSection]:$row[courseId]:$row[currentTerm]:$_POST[studentId]'><br></td>";
	echo "<td>" . $row['courseId'] . "</td>";
	echo "<td>" . $row['courseNumber'] . "</td>";
	echo "<td>" . $row['courseSection'] . "</td>";
	echo "<td>" . $row['courseName'] . "</td>";
	echo "<td>" . $row['currentTerm'] . "</td>";
	echo "<td>" . $row['time'] . "</td>";
	echo "<td>" . $row['faculty'] . "</td>";
	echo "<td>" . $row['location'] . "</td>";
	echo "</tr>";
    }

    echo "<button name='Submit'type='submit'>Submit</button>";	
    echo "</form>";
    mysql_close($con);
?>

</table>
<div id="c">
<div id="d"><br><br><a href="MainMenu.php">Home</a>
</body>
</html>
